#ifndef MEDICINESELECTDIALOG_H
#define MEDICINESELECTDIALOG_H

#include <QDialog>
#include <QTableWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QJsonArray>
#include "../../../Common/models.h"
#include "../../../Common/protocol.h"

class MedicineSelectDialog : public QDialog {
    Q_OBJECT
    
public:
    explicit MedicineSelectDialog(QWidget *parent = nullptr);
    ~MedicineSelectDialog();
    
    Medicine getSelectedMedicine() const { return m_selectedMedicine; }
    
private slots:
    void onSearchClicked();
    void onTableDoubleClicked(int row, int column);
    void onSelectClicked();
    void onMessageReceived(MessageType type, const QJsonObject& data);
    
private:
    void setupUI();
    void loadMedicines();
    void updateMedicineTable(const QJsonArray& medicines);
    
    QLineEdit* m_searchEdit;
    QPushButton* m_searchButton;
    QTableWidget* m_medicineTable;
    QPushButton* m_selectButton;
    QPushButton* m_cancelButton;
    
    QJsonArray m_medicines;
    Medicine m_selectedMedicine;
};

#endif // MEDICINESELECTDIALOG_H

